package com.jdaw.datastructure.queue;

public class ArrayQueue {
    private int maxSize;
    private int front;
    private int rear;
    private int[] array;

    //初始化的构造器
    public ArrayQueue(int maxSize){
        this.maxSize=maxSize;
        array=new int[maxSize];
        front=-1;
        rear=-1;
    }

    //判断队列是否满
    public boolean isFull(){
        return rear==maxSize-1;
    }

    //判断队列是否为空
    public boolean isEmpty(){
        return rear==front;
    }

    //添加数据到队列
    public boolean addQueue(int n){
        if(!isFull()){
            array[++rear]=n;
            return true;
        }
        return false;
    }

    //获取队列数据，出队列
    public int getQueue(){
        if(!isEmpty()){
            front++;
            return array[front];
        }
        throw new RuntimeException("队列为空不可取");
    }

    //展示队列所有数据
    public void showQueue(){
        if(!isEmpty()){
            for(int i=0;i<array.length;i++){
                System.out.println(array[i]);
            }
        }
    }
}

class AQdemo{
    public static void main(String[] args) {
        ArrayQueue arrayQueue=new ArrayQueue(3);
        arrayQueue.addQueue(2);
        arrayQueue.addQueue(5);
        arrayQueue.addQueue(6);
        System.out.println(arrayQueue.getQueue());
        arrayQueue.showQueue();
    }
}
